//
//  ZooUtil.m
//  ZooNgonDoiOS
//
//  Created by Trung sound on 6/20/12.
//  Copyright (c) 2012 Personal. All rights reserved.
//

#import "ZooUtil.h"

@implementation ZooUtil

+(NSString *) LoadTokenValue {
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *tokenValue = [defaults objectForKey:TOKEN_VALUE];
    return tokenValue;
}

+(NSString *) LoadTokenSecretValue {
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *tokenSecretValue = [defaults objectForKey:TOKEN_SECRET_VALUE];
    return tokenSecretValue;
}

+(void) SaveTokenKey:(NSString *) tokenValue tokenSecretValue:(NSString *) tokenSecretValue {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:tokenValue forKey:TOKEN_VALUE];
    [defaults setObject:tokenSecretValue forKey:TOKEN_SECRET_VALUE];
    [defaults synchronize];
}

+ (UIColor *)getColorFromHexa:(NSString *)from alpha:(CGFloat)alpha{
    UIColor *color = [UIColor whiteColor];
    @try {
        from = [from stringByReplacingOccurrencesOfString:@"#" withString:@""];
        if ([from length] == 6) {
            NSScanner *scanner;
            NSString *r = [from substringToIndex:2];
            unsigned int rfloat;
            scanner = [NSScanner scannerWithString:r];
            [scanner scanHexInt:&rfloat];
            
            NSRange range;
            range.length = 2;
            range.location = 2;
            NSString *b = [from substringWithRange:range];
            unsigned int bFload;
            scanner = [NSScanner scannerWithString:b];
            [scanner scanHexInt:&bFload];
            
            range.location = 4;
            NSString *g = [from substringWithRange:range];
            unsigned int gFload;
            scanner = [NSScanner scannerWithString:g];
            [scanner scanHexInt:&gFload];
            color = [UIColor colorWithRed:rfloat / 255.0f green:bFload / 255.0f blue:gFload / 255.0f alpha:alpha];
        }
    }
    @catch (NSException *exception) {
        NSLog(@"%@", exception);
    }
    @finally {
        
    }
    
    return color;
}

+ (id)copyWithZone:(NSZone *)zone {
    
}

+ (void)pushController:(UINavigationController *)navigationController toViewController:(UIViewController *)viewController transition:(UIViewAnimationTransition)transition {
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:.5];
    [UIView setAnimationBeginsFromCurrentState:YES];        
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:navigationController.view cache:NO];
    [navigationController pushViewController:viewController animated:NO];
    [UIView commitAnimations];

}

+ (void) showSimpleAlert: (NSString*) message {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:message delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
    
    [alertView show];
    [alertView release];
}
@end
